<template>
  <div class="page">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <b>预检打印申报书</b>
      </div>
      <div class="group_item">
        <div class="group_item_top">
          <span>操作说明</span>
        </div>
        <div class="group_item_content">
          <p>1.请务必仔细核对预检申报书，“检查无误，确认提交”后不可撤销，所有信息无法再更改；</p>
          <p>2.确认提交后会生成正式申报书，请打印正式申报书并签名盖章，上传至本系统。</p>
        </div>
      </div>
      <div class="group_item">
        <div class="group_item_top">
          <span>操作按钮</span>
        </div>
        <div class="group_item_content">
          <el-button @click="look(0)" type="primary" size="mini">查看预检申报书</el-button>
          <el-button @click="upload" type="primary" size="mini">检查无误，确认提交</el-button>
          <el-button v-if="lookshow" @click='downloadBook(1)' type="primary" size="mini">下载正式申报书</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script type="text/ecmascript-6">
import { pev, next } from "@/function/pevNext/pevNext.js";
export default {
  mounted() {
    this.getinfo();
  },
  data() {
    return {
      lookshow: false
    };
  },
  methods: {
    getinfo() {
      this.$http.get("/filing/process/info").then(res => {
        if (res.data.process === 7) {
          this.lookshow = true;
        }
      });
    },
    look(val) {
      let name = `是否查看预检申报书（Tips：如遇无法查看，请确认是否被浏览器拦截）`;
      if (val === 1) name = "是否下载正式申报书";
      this.$confirm(`${name}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消", 
        type: "warning"
      }).then(() => {
        let fileDownload = require("js-file-download");
        // 申报者——导出个人陈述信息PDF
        this.$http.get(`/filing/explain/info/pdf/${val}`, {
          responseType: "blob"
        });
        // 申报者——导出作者信息PDF
        this.$http.get(`/filing/student/info/pdf/${val}`, {
          responseType: "blob"
        });
        // 申报者——导出成绩PDF
        this.$http.get(`/filing/scorce/info/pdf/${val}`, {
          responseType: "blob"
        });
        // 申报者——导出指导专家PDF
        this.$http.get(`/filing/mentor/info/pdf/${val}`, {
          responseType: "blob"
        });
        // 申报者——导出指导专家PDF
        this.$http.get(`/filing/tutor/info/pdf/${val}`, {
          responseType: "blob"
        });
        // 申报者——导出项目信息PDF
        this.$http.get(`/filing/project/info/pdf/${val}`, {
          responseType: "blob"
        });
      });
    },
    pevs() {
      pev(this);
    },
    upload() {
      this.$confirm(
        `此操作将上传申报书, 上传之后<b style="color:red">不可更改!</b>, 是否继续?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          dangerouslyUseHTMLString: true,
          type: "warning"
        }
      ).then(() => {
        this.$http.post("/filing/sheet/add", {}).then(res => {
          if (res.data.success) {
            this.getinfo();
            this.$message({
              message: "确认成功！",
              type: "success"
            });
            setTimeout(() => {
              location.reload();
            }, 1000);
          } else {
            this.$message({
              message: res.data.message,
              type: "error"
            });
          }
        });
      });
    },
    // 下载正式申报书
    downloadBook() {
      this.look(1);
    }
  }
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
